#include <iostream>
#include <string>

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i  *  i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}

int main() {
    std::string numberStr;
    std::cin >> numberStr;
    
    if (numberStr.length() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int num1 = 0, num2 = 0, num3 = 0;
    bool isValid = true;

    for (int i = 0; i < 3; ++i) {
        if (numberStr[i] >= '0' && numberStr[i] <= '9') {
            num1 = num1  *  10 + (numberStr[i] - '0');
        } else {
            isValid = false;
            break;
        }
    }

    if (!isValid) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    for (int i = 1; i < 3; ++i) {
        if (numberStr[i] >= '0' && numberStr[i] <= '9') {
            num2 = num2  *  10 + (numberStr[i] - '0');
        } else {
            isValid = false;
            break;
        }
    }

    if (!isValid) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    num3 = numberStr[2] - '0';

    int number = num1  *  100 + num2  *  10 + num3;


    int primeClosest = number;
    while (!isPrime(primeClosest)) {
        --primeClosest;
    }
    std::cout << primeClosest << std::endl;

    return 0;
}
